<template>
  <div>
    <!-- 顶部面包屑标识与导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" style="font-weight: 16">
      <el-breadcrumb-item :to="{ path: '/' }">
        <i class="el-icon-s-promotion"></i>后台管理
      </el-breadcrumb-item>
      <el-breadcrumb-item>SPU台账</el-breadcrumb-item>
    </el-breadcrumb>
    <el-divider></el-divider>
    <!-- SPU列表 -->
    <el-table :data="tableData" border style="width: 100%">
      <el-table-column prop="id" label="ID" width="70" align="center"
                       :show-overflow-tooltip="true"></el-table-column>
      <el-table-column label="封面图片" width="180" align="center">
        <template slot-scope="scope">
          <el-image
              style="width: 150px;"
              :src="JSON.parse(scope.row.pictures)[0].url"
              fit="fit"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="brandName" label="品牌" width="100" align="center"
                       :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="categoryName" label="类别" width="100" align="center"
                       :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="name" label="商品" width="180" align="center">
        <template slot-scope="scope">
          <div>[{{ scope.row.typeNumber }}]</div>
          <div>{{ scope.row.name }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="title" label="商品标题" width="220" align="center"
                       :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="listPrice" label="售价" width="80" align="center"></el-table-column>
      <el-table-column prop="stock" label="库存" width="80" align="center"></el-table-column>
      <el-table-column prop="sales" label="销量" width="80" align="center"></el-table-column>
      <el-table-column label="好评/评论" width="100" align="center">
        <template slot-scope="scope">
          <div>{{ scope.row.positiveCommentCount }}</div>
          <div>/</div>
          <div>{{ scope.row.commentCount }}</div>
        </template>
      </el-table-column>
      <el-table-column prop="sort" label="排序序号" width="80" align="center"></el-table-column>
      <el-table-column label="发布" width="100" align="center">
        <template slot-scope="scope">
          <el-tooltip content="Top center" placement="top">
            <span v-if="scope.row.isPublished==1" style="color: #67c23a">已发布</span>
            <span v-else style="color: #F56C6C">未发布</span>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column prop="isNewArrival" label="新品" width="100" align="center">
        <template slot-scope="scope">
          <el-switch
              @change="toggleNewArrival(scope.row)"
              v-model="scope.row.isNewArrival"
              :active-value="1"
              :inactive-value="0"
              active-color="#13ce66"
              inactive-color="#cccccc">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="推荐" width="100" align="center">
        <template slot-scope="scope">
          <el-switch
              @change="toggleRecommend(scope.row)"
              v-model="scope.row.isRecommend"
              :active-value="1"
              :inactive-value="0"
              active-color="#13ce66"
              inactive-color="#cccccc">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="SKU管理" width="180" align="center">
        <template slot-scope="scope">
          <el-button @click="gotoSkuManagement(scope.row)">SKU管理</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="180" align="center">
        <template slot-scope="scope">
          <el-button class="op_button" @click="openCheckDialog(scope.row)">审核</el-button>
          <el-button class="op_button" @click="openShowInfoDialog(scope.row)">查看</el-button>
          <el-button class="op_button" @click="openEditDialog(scope.row)">编辑</el-button>
          <el-button class="op_button danger" @click="openDeleteConfirm(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <div style="margin: 10px 0; text-align: right;">
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="pageSize"
          layout="total,prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>
    <!-- 显示SPU详情的对话框-->
    <el-dialog class="spu-info" :title="spuInfo.name" :visible.sync="infoDialogVisible">
      <!-- 描述列表 -->
      <el-descriptions :column="1" border label-class-name="spu-info-label">
        <el-descriptions-item label="数据ID">
          3
          <el-tooltip class="item" effect="dark" content="此数据不会显示在普通用户界面" placement="right">
            <sup><i class="el-icon-info"></i></sup>
          </el-tooltip>
        </el-descriptions-item>
        <el-descriptions-item label="类别">{{ spuInfo.categoryName }}</el-descriptions-item>
        <el-descriptions-item label="品牌">{{ spuInfo.brandName }}</el-descriptions-item>
        <el-descriptions-item label="商品名称">{{ spuInfo.name }}</el-descriptions-item>
        <el-descriptions-item label="货号">{{ spuInfo.typeNumber }}</el-descriptions-item>
        <el-descriptions-item label="标题">{{ spuInfo.title }}</el-descriptions-item>
        <el-descriptions-item label="简介">{{ spuInfo.description }}</el-descriptions-item>
        <el-descriptions-item label="计件单位">{{ spuInfo.unit }}</el-descriptions-item>
        <el-descriptions-item label="售价">{{ spuInfo.listPrice }} 元</el-descriptions-item>
        <el-descriptions-item label="销量">{{ spuInfo.sales }}</el-descriptions-item>
        <el-descriptions-item label="库存">{{ spuInfo.stock }}</el-descriptions-item>
        <el-descriptions-item label="库存阈警值">{{ spuInfo.stockThreshold }}</el-descriptions-item>
        <el-descriptions-item label="关键词">{{ spuInfo.keywords }}</el-descriptions-item>
        <el-descriptions-item label="标签">{{ spuInfo.tags }}</el-descriptions-item>
        <el-descriptions-item label="排序序号">{{ spuInfo.sort }}</el-descriptions-item>
        <el-descriptions-item label="商品图片">
          <el-image class="picture-item"
                    v-for="picture in JSON.parse(spuInfo.pictures)"
                    :key="picture.id"
                    :src="picture.url"
                    fit="cover"></el-image>
        </el-descriptions-item>
        <el-descriptions-item label="商品详情"><span v-html="spuInfo.detail"></span></el-descriptions-item>
      </el-descriptions>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="infoDialogVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
    <!-- 显示SPU编辑的对话框-->
    <el-dialog :title="spuInfo.name" :visible.sync="infoEditDialogVisible">
      <el-form :model="editForm" :rules="rules" ref="editForm" label-width="100px">
        <el-form-item label="商品类别" prop="categoryId">
          <!-- 商品类别选择器 -->
          <el-cascader
              style="width: 100%;"
              placeholder="请选择父级类别"
              v-model="editForm.categoryId"
              :options="categoryOptions"
              :props="{ expandTrigger: 'hover' }">
          </el-cascader>
        </el-form-item>
        <el-form-item label="品牌" prop="brandId">
          <el-select v-model="editForm.brandId" placeholder="请选择品牌">
            <el-option
                v-for="item in brandListOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="属性模板" prop="attributeTemplateId">
          <el-select v-model="editForm.attributeTemplateId" placeholder="请选择属性模板">
            <el-option
                v-for="item in attributeTemplateOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="商品名称" prop="name">
          <el-input v-model="editForm.name"></el-input>
        </el-form-item>
        <el-form-item label="标题" prop="title">
          <el-input v-model="editForm.title"></el-input>
        </el-form-item>
        <el-form-item label="简介" prop="description">
          <el-input v-model="editForm.description"></el-input>
        </el-form-item>
        <el-form-item label="货号" prop="typeNumber">
          <el-input v-model="editForm.typeNumber"></el-input>
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="计件单位" prop="unit">
              <el-input v-model="editForm.unit"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="售价" prop="listPrice">
              <el-input v-model="editForm.listPrice">
                <template slot="append">元</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="库存" prop="stock">
              <el-input v-model="editForm.stock">
                <template slot="append">部</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="库存预警值" prop="stockThreshold">
              <el-input v-model="editForm.stockThreshold">
                <template slot="append">部</template>
              </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="关键词" prop="keywords">
          <el-input v-model="editForm.keywords"></el-input>
        </el-form-item>
        <el-form-item label="标签" prop="tags">
          <el-input v-model="editForm.tags"></el-input>
        </el-form-item>
        <el-form-item label="排序序号" prop="sort">
          <el-input v-model="editForm.sort"></el-input>
        </el-form-item>
        <el-form-item label="商品详情">
          <div id="wangEditor"></div>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('editForm')">提交</el-button>
          <el-button @click="resetForm('editForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>

export default {
  data() {
    return {
      // 表格数据
      tableData: [],
      // 分页相关数据
      // 当前页码
      currentPage: this.$router.currentRoute.query.page ? parseInt(this.$router.currentRoute.query.page) : 1,
      // 最大页码
      maxPage: 5,
      // 每页记录数据
      pageSize: 5,
      // 记录总数
      total: 0,
      // SPU详情
      spuInfo: {
        pictures: '[]',
      },
      // SPU详情对话框的可见性
      infoDialogVisible: false,
      // SPU编辑表单
      editForm: {
        id: '',
        categoryId: '',
        categoryName: '',
        brandId: '',
        brandName: '',
        attributeTemplateId: '',
        attributeTemplateName: '',
        name: 'Redmi Note 11 5G',
        title: 'Redmi Note 11 5G 天玑810 33W Pro快充 5000mAh大电池 6GB +128GB 浅梦星河',
        description: '【品质好物】天玑810，5000mAh大电池【Note11SE火热抢购中】',
        typeNumber: '100028235472',
        unit: '部',
        listPrice: '1199',
        stock: '5000',
        stockThreshold: '500',
        keywords: '小米,红米,智能手机',
        tags: '5G手机,快充手机,大容量电池手机',
        sort: '95',
        detail: ''
      },
      // 表单规则
      rules: {
        brandId: [
          {type: 'number', required: true, message: '请选择品牌', trigger: 'blur'},
        ],
        attributeTemplateId: [
          {type: 'number', required: true, message: '请选择属性模板', trigger: 'blur'},
        ],
        name: [
          {required: true, message: '请输入商品名称', trigger: 'blur'},
        ],
        title: [
          {required: true, message: '请输入标题', trigger: 'blur'},
        ],
        description: [
          {required: true, message: '请输入简介', trigger: 'blur'},
        ],
        unit: [
          {required: true, message: '请输入计件单位', trigger: 'blur'},
        ],
        listPrice: [
          {required: true, message: '请输入售价', trigger: 'blur'},
        ],
        typeNumber: [
          {required: true, message: '请输入货号', trigger: 'blur'},
        ],
        stock: [
          {required: true, message: '请输入库存', trigger: 'blur'},
        ],
        stockThreshold: [
          {required: true, message: '请输入库存阈警值', trigger: 'blur'},
        ],
        keywords: [
          {required: true, message: '请输入关键词', trigger: 'blur'},
        ],
        tags: [
          {required: true, message: '请输入标签', trigger: 'blur'},
        ],
        sort: [
          {required: true, message: '请输入排序序号', trigger: 'blur'},
        ],
      },
      // 类别下拉菜单的选项数据
      categoryOptions: [],
      // 品牌的下拉菜单的选项数据
      brandListOptions: [],
      // 属性模板的下拉菜单的选项数据
      attributeTemplateOptions: [],
      // 富文本编辑器
      editor: {},
      formLabelWidth: '120px',
      // SPU详情编辑对话框的可见性
      infoEditDialogVisible: false

    }
  },
  watch: {
    infoEditDialogVisible(newVal) {
      if (newVal) {
        this.$nextTick(() => {
          this.initWangEditor();
        });
      }
    },
  },
  methods: {
    // 切换【是否新品】状态
    toggleNewArrival(spu) {
      let isNewArrivalText = ['非新品', '新品'];
      let url = ' http://localhost:9180/spu/' + spu.id;
      if (spu.isNewArrival == 1) {
        url += '/setIsNewArrival';
      } else {
        url += '/setNoNewArrival';
      }
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .post(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          let message = '将SPU【' + spu.name + '】的是否新品状态修改为【' + isNewArrivalText[spu.isNewArrival] + '】成功！';
          this.$message({
            message: message,
            type: 'success'
          })
          this.loadSpuList();
        } else if (jsonResult.state == 40400) {
          this.$alert(jsonResult.message, '操作失败', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadSpuList();
            }
          });
        } else {
          this.$alert(jsonResult.message, '操作失败', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    // 切换【是否推荐】状态
    toggleRecommend(spu) {
      let isRecommendText = ['非新品', '新品'];
      let url = ' http://localhost:9180/spu/' + spu.id;
      if (spu.isRecommend == 1) {
        url += '/setIsRecommend';
      } else {
        url += '/setNoRecommend';
      }
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .post(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          let message = '将SPU【' + spu.name + '】的是否新品状态修改为【' + isRecommendText[spu.isRecommend] + '】成功！';
          this.$message({
            message: message,
            type: 'success'
          })
          this.loadSpuList();
        } else if (jsonResult.state == 40400) {
          this.$alert(jsonResult.message, '操作失败', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadSpuList();
            }
          });
        } else {
          this.$alert(jsonResult.message, '操作失败', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    // 跳转到SKU管理页
    gotoSkuManagement(spu) {
      // 点击跳转按钮时把spuId存到内存中，在sku列表页面再取出，增加安全性
      localStorage.setItem('localSpuId', spu.id);
      console.log('spuId='+spu.id);
      this.$router.push('/sys-admin/product/spu-list');
      // this.$router.push('/sys-admin/product/spu-list?spuId='+spu.id);
    },
    // 打开审核对话框
    openCheckDialog(spu) {
      let title = '提示';
      let message = '您正在尝试审核【' + spu.id + '-' + spu.name + '】的SPU数据，抱歉，此功能尚未实现……';
      this.$alert(message, title, {
        confirmButtonText: '确定',
        callback: action => {
        }
      });
    },
    // 打开查看对话框
    openShowInfoDialog(spu) {
      let url = 'http://localhost:9180/spu/fullInfo/' + spu.id;
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.spuInfo = jsonResult.data;
          this.infoDialogVisible = true;
        } else {
          this.$alert(jsonResult.message, '警告', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadSpuList();
            }
          });
        }
      })
    },
    // 打开编辑对话框
    openEditDialog(spu) {
      let url = 'http://localhost:9180/spu/edit/' + spu.id;
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.editForm = jsonResult.data;
          this.infoEditDialogVisible = true;

          // 确保编辑器初始化后设置数据
          this.$nextTick(() => {
            this.initWangEditor();
            this.editor.txt.html(this.editForm.detail || '');
          });

          this.loadCateListTree();
          this.loadBrandList();
          this.loadAttributeTemplateList();
        } else {
          this.$alert(jsonResult.message, '警告', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadSpuList();
            }
          });
        }
      })
    },
    // 加载类别树数据
    loadCateListTree() {
      let url = 'http://localhost:9180/categories/listTree';
      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.categoryOptions = jsonResult.data;
        }
      })
    },
    // 加载品牌列表
    loadBrandList() {
      let url = 'http://localhost:9180/brands?queryType=all';
      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.brandListOptions = jsonResult.data.list;
        }
      })
    },
    // 加载属性模板列表
    loadAttributeTemplateList() {
      let url = 'http://localhost:9180/attribute-template?queryType=all';
      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.attributeTemplateOptions = jsonResult.data.list;
        }
      })
    },
    // 初始化富文本编辑器
    initWangEditor() {
      // 确保编辑器的容器元素存在且可见
      const editorContainer = document.querySelector('#wangEditor');
      if (editorContainer) {
        // 初始化编辑器
        this.editor = new this.wangEditor(editorContainer);
        this.editor.config.onchange = (newHtml) => {
          this.editForm.detail = newHtml;
        };
        this.editor.config.zIndex = 1;
        this.editor.create();
        // 设置后台数据
        this.editor.txt.html(this.editForm.detail || '');
      }
    },
    // 提交表单
    submitForm(formName) {
      if (Array.isArray(this.editForm.categoryId)) {
        this.editForm.categoryId = this.editForm.categoryId.pop();
      }
      this.$refs[formName].validate((valid) => {
        if (valid) {

          // 查询类别详情，判断类别是否存在，是否有子级，是否被禁用
          let url = 'http://localhost:9180/categories/' + this.editForm.categoryId;
          console.log('categoryId=' + this.editForm.categoryId);

          let localJwt = localStorage.getItem('localJwt');
          this.axios.create({'headers': {'Authorization': localJwt}})
              .get(url).then((response) => {
            let jsonResult = response.data;
            if (jsonResult.state == 20000) {
              let category = jsonResult.data;
              // 检查该类别下是否还有子级类别
              if (category.isParent == 0) {
                // 检查该类别是否被禁用
                if (category.enable == 1) {
                  this.editForm.categoryName = category.name;
                  console.log('categoryName=' + this.editForm.categoryName);

                  // 检查品牌是否存在，是否被禁用
                  let url = 'http://localhost:9180/brands/' + this.editForm.brandId;
                  console.log('url=' + url);

                  let localJwt = localStorage.getItem('localJwt');
                  this.axios.create({'headers': {'Authorization': localJwt}})
                      .get(url).then((response => {
                    let jsonResult = response.data;
                    if (jsonResult.state == 20000) {
                      // 检查是否被禁用
                      let brand = jsonResult.data;
                      if (brand.enable == 1) {
                        this.editForm.brandName = brand.name;
                        console.log('brandName=' + this.editForm.brandName);

                        // 检查属性模板是否存在
                        url = 'http://localhost:9180/attribute-template/' + this.editForm.attributeTemplateId;
                        console.log('url=' + url);

                        this.axios.create({'headers': {'Authorization': localJwt}})
                            .get(url).then((response => {
                          let jsonResult = response.data;
                          if (jsonResult.state == 20000) {
                            let attributeTemplate = jsonResult.data;
                            this.editForm.attributeTemplateName = attributeTemplate.name;
                            console.log('attributeTemplateName=' + this.editForm.attributeTemplateName);

                            // 执行更新
                            url = 'http://localhost:9180/spu/' + this.editForm.id + '/update';
                            console.log('url = ' + url);

                            this.editForm.detail = this.editor.txt.html();
                            let formData = this.qs.stringify(this.editForm);
                            console.log('editForm = ' + JSON.stringify(this.editForm));
                            console.log('formData = ' + formData);

                            this.axios.create({'headers': {'Authorization': localJwt}})
                                .post(url, formData).then((response) => {
                              let jsonResult = response.data;
                              if (jsonResult.state == 20000) {
                                let message = '修改SPU成功！';
                                this.$alert(message, '提示', {
                                  confirmButtonText: '确定',
                                  callback: action => {
                                    this.infoEditDialogVisible = false;
                                    this.loadSpuList();
                                  }
                                });
                              } else {
                                let message = jsonResult.message;
                                this.$alert(message, '警告', {
                                  confirmButtonText: '确定',
                                  callback: action => {
                                  }
                                });
                              }
                            });

                          } else {
                            this.$alert(jsonResult.message, '错误', {
                              confirmButtonText: '确定',
                              callback: action => {
                                this.loadAttributeTemplateList();
                              }
                            });
                          }
                        }))


                      } else {
                        let message = "错误，所选类别已禁用！";
                        this.$alert(message, '错误', {
                          confirmButtonText: '确定',
                          callback: action => {
                          }
                        });
                      }
                    } else {
                      his.$alert(jsonResult.message, '错误', {
                        confirmButtonText: '确定',
                        callback: action => {
                          this.loadBrandList();
                        }
                      });
                    }
                  }))


                } else {
                  let message = "错误，选择的类别已被禁用！";
                  this.$alert(message, '错误', {
                    confirmButtonText: '确定',
                    callback: action => {
                    }
                  });
                }
              } else {
                let message = "错误，选择的类别必须不包含子级类别！";
                this.$alert(message, '错误', {
                  confirmButtonText: '确定',
                  callback: action => {
                  }
                });
              }
            } else {
              this.$alert(jsonResult.message, '错误', {
                confirmButtonText: '确定',
                callback: action => {
                  this.loadCateListTree();
                }
              });
            }
          })

        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    // 重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    // 删除按钮
    openDeleteConfirm(spu) {
      this.$confirm('此操作将永久删除【' + spu.id + '-' + spu.name + '】SPU, 是否继续？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(spu);
      }).catch(() => {
      });
    },
    // 删除SPU
    handleDelete(spu) {
      let url = 'http://localhost:9180/spu/' + spu.id + '/delete';
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .post(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.$message({
            type: 'success',
            message: '删除相册成功!'
          });
          this.loadSpuList();
        } else if (jsonResult.state == 40400) {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadSpuList();
            }
          });
        } else {
          this.$alert(jsonResult.message, '错误', {
            confirmButtonText: '确定',
            callback: action => {
            }
          });
        }
      })
    },
    // 加载SPU列表
    loadSpuList() {
      let page = this.$router.currentRoute.query.page;
      if (!page || page < 1) {
        page = 1;
      }
      let url = 'http://localhost:9180/spu?page=' + page;
      console.log('url=' + url);

      let localJwt = localStorage.getItem('localJwt');
      this.axios.create({'headers': {'Authorization': localJwt}})
          .get(url).then((response) => {
        let jsonResult = response.data;
        if (jsonResult.state == 20000) {
          this.tableData = jsonResult.data.list;
          this.currentPage = jsonResult.data.currentPage;
          this.maxPage = jsonResult.data.maxPage;
          this.pageSize = jsonResult.data.pageSize;
          this.total = jsonResult.data.total;
        }
      })

    },
    // 切换分页
    handleCurrentChange(page) {
      this.$router.replace('?page=' + page);
      this.loadSpuList();
    }
  },
  mounted() {
    this.loadSpuList();
    this.initWangEditor();
  }
};
</script>
<style>
.op_button {
  width: 50px;
  margin: 5px 6px;
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 3px;
}

.danger {
  background: #F56C6C;
  color: #fff;
}

.spu-info .spu-info-label {
  width: 120px;
}

.danger:hover {
  background: #f92d2d;
  color: #fff;
}

.spu-info .picture-item {
  width: 80px;
  height: 80px;
  margin-right: 16px;
  margin-bottom: 10px;
  border-radius: 3px;
  float: left;
}
</style>